#!/bin/bash
kubectl get ns -A -l "namespace=task"| awk '{print $1}' > ns.txt
sed -i '1d' ns.txt
while read line
do
etcdctl del /registry/serviceaccounts/$line/default
done < ns.txt

kubectl get pvc -A -l "pvc=nfs" | awk '{print $2}' > pvc.txt
sed -i '1d' pvc.txt
while read line
do
arr=(${line//-/ }) 
pvc_ns=${arr[0]}
#kubectl patch pvc $line -p '{"metadata":{"finalizers":null}}' -n $pv_ns
etcdctl del /registry/persistentvolumeclaims/$pvc_ns/$line
done < pvc.txt


kubectl get pv | awk '{print $1}' > pv.txt
sed -i '1d' pv.txt
while read line
do
#kubectl patch pv $line -p '{"metadata":{"finalizers":null}}'
etcdctl del /registry/persistentvolumes/$line
done < pv.txt

while read line
do
etcdctl del /registry/namespaces/$line
done < ns.txt

